<?php

final class Html {

    private static $instance = null;

    private function __construct() {
        
    }

    public static function getInstance() {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function css($name) {
        echo '<link rel="stylesheet" type="text/css" href="' . SITE_ROOT . 'css/' . $name . '.css"/>';
    }

    public function script($name, $type = 'text/javascript') {
        echo '<script type="' . $type . '" src="' . SITE_ROOT . 'scripts/' . $name . '.js"></style>';
    }

    public function image($src, array $options = array()) {
        echo '<img src="' . SITE_ROOT . 'images/' . $src . '" ' . $this->optionsToString($options) . '/>';
    }

    public function link($title, array $path = array(), $htmlTag = null, $htmlClass = null) {
        if (isset($htmlTag)) {
            echo '<', $htmlTag;
            if (isset($htmlClass)) {
                echo ' class="', $htmlClass, '"';
            }
            echo '>';
        }
        echo '<a href="' . URL::getInstance()->createUrl($path) . '">' . $title . '</a>';
        if (isset($htmlTag)) {
            echo '<', $htmlTag, '>';
        }
    }

    private function optionsToString(array $options) {
        $str = '';
        foreach ($options as $key => $val) {
            $str .= $key . '="' . $val . '" ';
        }
        return $str;
    }

}

?>
